package controllers

import (
	"github.com/kataras/iris"
	"github.com/spf13/viper"
	"irisfarm/app/repositories"
	"irisfarm/app/services"
)

type ExampleController struct {
	BaseController
}

// example
func (c *ExampleController) Index(ctx iris.Context) {
	c.Init(ctx)

	c.output.Success("this is a example")
}

// example model
func (c *ExampleController) Model(ctx iris.Context) {
	c.Init(ctx)

	es := services.ExampleService{}

	c.output.Success(es.GetName())
}

// example config
func (c *ExampleController) Config(ctx iris.Context) {
	c.Init(ctx)

	c.output.Success(viper.GetString("mysql.driver"))
}

// example repository
func (c *ExampleController) Repository(ctx iris.Context) {
	c.Init(ctx)

	r := repositories.ExampleRepository{}
	result, err := r.SayHello()

	if err != nil {
		c.output.Message(err.Error())
		return
	}

	c.output.Success(result)
}
